package com.netty.prictice.second;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

import java.util.Date;

/**
 * @author shengtao
 * @Description:
 * @date 2018/09/05 16:21
 */
public class TimeClientHandler extends ChannelHandlerAdapter {

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf message = (ByteBuf) msg;
        try {
            long currentTimeMillis = (message.readUnsignedInt() - 2208988800L) * 1000L;
            System.out.println("server Timer:"+new Date(currentTimeMillis));
            ctx.close();
        }finally {
            message.release();
        }
    }
}
